#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

class Solution1 {
public:
    vector<int> findAnagrams(string s, string p) {
        vector<int> ret;
        int hash1[26] = { 0 };
        int len = p.size();
        for (auto ch : p)
        {
            hash1[ch - 'a']++;
        }
        int hash2[26] = { 0 };
        for (int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            char in = s[right];
            //hash2[in - 'a']++;
            if (++hash2[in - 'a'] <= hash1[in - 'a'])
            {
                count++;
            }
            if (right - left + 1 > len)
            {
                char out = s[left];
                if (hash2[out - 'a']-- <= hash1[out - 'a'])
                {
                    count--;
                }
                //hash2[out - 'a']--;
                left++;
            }
            if (count == len)
            {
                ret.push_back(left);
            }
        }
        return ret;
    }
};

class Solution2 {
public:
    int totalFruit(vector<int>& fruits) {
        int hash[100001] = { 0 };
        int ret = 0;
        for (int left = 0, right = 0, kind = 0; right < fruits.size(); right++)
        {
            if (hash[fruits[right]] == 0)
                kind++;
            hash[fruits[right]]++;
            while (kind > 2)
            {
                hash[fruits[left]]--;
                if (hash[fruits[left]] == 0)
                    kind--;
                left++;
            }
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};


int main()
{

    return 0;
}